<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>share</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet"/>
<link href="${pageContext.request.contextPath }/css/layer.css"
	rel="stylesheet"/>
<script src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath }/js/layer.js"></script>
	<script src="/js/public-method.js"></script>
</head>
<body>
	<div class="content">
		<div class="top">
			<%@include file="top.jsp"%>
		</div>
		<div style="margin-top: 80px;">
			<div class="panel panel-default"
				style="margin-left: 100px; width: 80%; float: left;margin-top: 20px;">
				<!-- Default panel contents -->
				<div class="panel-heading" id="pathnav">
					<div class="row">
					<div class="col-lg-1">
						<div class="input-group ">
							<span class="input-group-btn">
								<a class="btn btn-primary" target="_blank" onclick="return downloadFile(this)"style="margin-left: 850px;">下载</a>
								<a class="btn btn-primary" target="_blank" onclick="return saveShare(this)" style="margin-left: 20px;">保存到网盘</a>
							</span>
						</div>
					</div>
					</div>
				</div>
				<input type="hidden" id="fileId">
				<input type="hidden" id="toId"  value="xxx" />
				<table class="table table-hover" id="mytable">
					<thead>
						<tr>
							<th colspan="2" width="70%">文件名</th>
							<th>大小</th>
							<th>分享时间</th>
						</tr>
					</thead>
					<tbody id = "tbody">

					</tbody>
				</table>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
    $(document).ready(function() {
        getFiles();
    });
    /**获取文件列表*/
    function getFiles() {
        var id =getQueryString("id");
        $.ajax({
            url: "../shares/showShare",
            type: "POST",
            data: {"shareId" : id,},
            success: function (data) {
                var str = "";
                var tbody = document.getElementById("tbody");
                var input=document.getElementById("fileId");
                input.value=data.files.fileId;
                tbody.innerHTML="";
                str += "<tr>" +
                    "<td colspan=\"2\" width=\"60%\">";
                switch (data.files.filetypeId) {
                    case 1:
                        str += "<img src=\"../img/yyc-images/filetype/mp4.png\" width=\"4%\">" + "&nbsp;"+data.files.fileName + "</td>";
                        break;
                    case 2:
                        str += "<img src=\"../img/yyc-images/filetype/text.png\" width=\"4%\">" + "&nbsp;"+data.files.fileName + "</td>";
                        break;
                    case 3:
                        str += "<img src=\"../img/yyc-images/filetype/mp3.png\" width=\"4%\">" +"&nbsp;"+data.files.fileName + "</td>";
                        break;
                    case 4:
                        str += "<img src=\"../img/yyc-images/filetype/png.png\" width=\"4%\">" +"&nbsp;"+data.files.fileName + "</td>";
                        break;
                    case 5:
                        str += "<img src=\"../img/yyc-images/filetype/icon.png\" width=\"4%\">" + "&nbsp;"+data.files.fileName + "</td>";
                        break;
                    case 6:
                        str += "<img src=\"../img/yyc-images/filetype/other.png\" width=\"4%\">" + "&nbsp;"+data.files.fileName + "</td>";
                        break;
                }
                str += "<td>"
                if (data.files.filetypeId == 5) {
                    str += "--";
                }
                else {
                    str += data.files.fileFullSize;
                }"</td>";
                str += "<td>" + data.shareTime + "</td></tr>";
                tbody.innerHTML += str;
            },
            error:function (data) {
                alert("操作失败");
            }
        });
    }
    /**导航点击*/
    function theClick(obj) {
        getFiles($(obj).attr("path"));
        $(obj).nextAll().remove();
        return false;
    }
    /**导航栏添加导航*/
    function navPath(path, currentPath) {
        $("#navPath").append(
            '<a href="#" path="' + path
            + '" onclick="return theClick(this)">&nbsp;'
            + currentPath + '&nbsp;&#62;</a>');
    }
    /**当前分享文件首页*/
    function allFile() {
        window.location.reload();
        return false;
    }

    /**
     * 下载
     */
    function downloadFile(){
        var id=document.getElementById("fileId").value;
        window.location.href="../files/downloadFile?ids=" +id;
    }

    /*
    保存
    */
    function saveShare(){
        var idstr=document.getElementById("fileId").value;
            //设置隐藏域的值
            document.getElementById("toId").value=idstr;
            top.layer.open({
                type: 2,			//0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                tilte: '复制到',
                area: ['800px', '500px'],
                shade: 0.6,			//遮罩透明度，默认：0.3
                shadeclose: false,	//控制点击弹层外区域关闭，默认：false
                fixed: false, 		//鼠标滚动时，层是否固定在可视区域，默认：true
                maxmin: false,		//是否允许全屏最小化，默认：false
                resize: false,		//是否允许拉伸，默认：true
                anim: 0,				//0-6的动画形式，-1不开启，默认0
                scrollbar: true,		//是否允许浏览器出现滚动条，默认：true
                move: false,			//触发拖动的元素，默认是触发标题区域拖拽
                closeBtn: 0,			//提供了两种风格的关闭按钮，可通过配置1和2来展示,如果不显示，则closeBtn: 0，默认：1
                content: 'relocation.jsp?ids='+idstr,
                btn: ['确定', '取消'],
                yes: function(index,layero){
                    /*想移动到这个位置*/
                    var toId=document.getElementById("toId").value;
                    $.ajax({
                        url:"../files/copyFiles",
                        type:"post",
                        data:{
                            "files":idstr,
                            "copyto":toId
                        },
                        success:function (data) {
                            alert("复制文件成功");
                        },
                        error:function (data) {
                            alert("复制文件异常")
                        }

                    });
                    layer.close(index);
                },
                btn2: function(index,layero){
                    layer.close(index);}
            });
        return false;
    }
</script>
</html>
